/**
 * @author
 * @createtime
 * @class NoticeForm
 * @extends Ext.Window
 * @description News表单
 * @company KZW
 */
NoticeForm = Ext.extend(Ext.Window, {
			imagePanlbar : null,
			// 构造函数
			constructor : function(_cfg) {
				Ext.applyIf(this, _cfg);
				// 必须先初始化组件
				this.initUIComponents();
				NoticeForm.superclass.constructor.call(this, {
					id : 'NoticeFormWin',
					layout : 'fit',
					items : this.formPanel,
					modal : true,
					height : 600,
					width : 860,
					iconCls : 'menu-notice',
					title : '公告详细信息',
					buttonAlign : 'center',
					buttons : [{
						text : '保存',
						iconCls : 'btn-save',
						scope : this,
						handler : this.save
					}, {
						text : '取消',
						iconCls : 'btn-cancel',
						scope : this,
						handler : this.cancel
					}]
				});
			},// end of the constructor
			// 初始化组件
			initUIComponents : function() {
				var me = this;
				this.formPanel = new Ext.FormPanel({
							border: false,
							bodyStyle : 'padding:10px',
							layout : {
								type: 'table',
								columns : 3
							},
							labelWidth : 80,
							defaults : {
								xtype : "textfield",
								anchor : '95%',
								labelAlign: 'right'
							},
							items : [{
									xtype : 'hidden',
									name : 'test'
								}, {
									xtype : 'hidden',
									name : 'news.attachIds'
								}, {
									xtype : 'hidden',
									name : 'news.attachNames'
								}, {
									xtype : 'hidden',
									name : 'news.recDepIds'
								}, {
									name : 'news.newsId',
									xtype : 'hidden',
									value : this.newsId == null ? '' : this.newsId
								}, {
									fieldLabel : '是否公告',
									name : 'news.isNotice',
									xtype : 'hidden',
									value : 1  // 是公告
								}, {
									fieldLabel : '公告标题',
									name : 'news.subject',
									allowBlank : false
								}, {
									fieldLabel : '创建时间',
									name : 'news.createtime',
									allowBlank : false,
									xtype : 'datefield',
									format : 'Y-m-d',
									value : new Date()
								}, {
									fieldLabel : '失效时间',
									name : 'news.expTime',
									xtype : 'datefield',
									format : 'Y-m-d'
								}, {
									fieldLabel : '发布人',
									name : 'news.issuer',
									allowBlank : false,
									maxLength : 32,
									value : curUserInfo.fullname
								}, {
									fieldLabel : '状态',
									name : 'news.status',
									allowBlank : false,
									xtype : 'combo',
									editable : false,
									mode : 'local',
									triggerAction : 'all',
									store : [['0', '禁用'], ['1', '激活']],
									value : 1
								}, {
									fieldLabel : '顺序',
									name : 'news.sn',
									xtype : 'numberfield'
								}, {
									colspan: 3,
									xtype : 'fieldcontainer',
									fieldLabel : '发布范围',
									layout: 'hbox',
									anchor : '98%',
									items : [{
												xtype : 'textarea',
												name : 'news.recDepNames',
												allowBlank : true,
												readOnly : true,
												width: 630
											}, {
												xtype : 'button',
												text : '选择范围',
												margin: '0 0 0 5',				
												iconCls : 'btn-select',
												scope : this,
												handler : function() {
													//单位可以多选
													DepSelector.getView(function(ids, names) {
														me.formPanel.getCmpByName('news.recDepNames').setValue(names);
														me.formPanel.getCmpByName('news.recDepIds').setValue(ids);
													}).show();
												}
											}]
								}, {
									anchor : '98%',
									colspan: 3,
									fieldLabel : '内容',
									name : 'news.content',
									allowBlank : false,
									height : 250,
									width: '100%',
									xtype : 'htmleditor'
								}, {
									colspan: 3,
									xtype: 'fieldcontainer',
									fieldLabel : '附件',
									layout: 'fit',
									items: [{
										xtype : 'attachpanel',
										gridWidth: 550,
										fileCat : 'news',
										name : 'newsAttachPanel'
									}]
								}]
						});
				// 加载表单对应的数据
				if (this.newsId != null && this.newsId != 'undefined') {
					var fPanel = this.formPanel;
					fPanel.loadData({
						url : __ctxPath + '/info/getNews.do?newsId='+ this.newsId,
						root : 'data',
						preName : 'news',
						success : function(response,options) {
							var news=Ext.util.JSON.decode(response.responseText).data;
							fPanel.getCmpByName('news.createtime').setValue(new Date(getDateFromFormat(news.createtime,'yyyy-MM-dd HH:mm:ss')));
							if(news.expTime != null && news.expTime != ""){								
								fPanel.getCmpByName('news.expTime').setValue(new Date(getDateFromFormat(news.expTime,'yyyy-MM-dd HH:mm:ss')));
							}
							
							//附件：加载附件
							var newsAttachPanel = me.formPanel.getCmpByName('newsAttachPanel');
							var v3 = me.formPanel.getCmpByName('news.attachIds').getValue();
							newsAttachPanel.loadByIds(v3);
							
						},
						failure : function(response,options) {
							Ext.ux.Toast.msg('编辑', '载入失败');
						}
					});
				}

			},// end of the initcomponents

			/**
			 * 重置
			 * 
			 * @param {}
			 *            formPanel
			 */
			reset : function() {
				this.formPanel.getForm().reset();
			},
			/**
			 * 取消
			 * 
			 * @param {}
			 *            window
			 */
			cancel : function() {
				this.close();
			},
			/**
			 * 保存记录
			 */
			save : function() {
				////附件：文书处理
				var newsAttachPanel = this.formPanel.getCmpByName('newsAttachPanel');
				this.formPanel.getCmpByName('news.attachIds').setValue(newsAttachPanel.getFileIds());
				this.formPanel.getCmpByName('news.attachNames').setValue(newsAttachPanel.getFileNames());
				$postForm({
					formPanel : this.formPanel,
					scope : this,
					url : __ctxPath + '/info/saveNews.do',
					callback : function(fp, action) {
						//刷新公告管理
						var gridPanel = Ext.getCmp('NewsGrid');
						if (gridPanel != null) {
							gridPanel.getStore().reload();
						}
						//刷新个人桌面
						var gridPanel = Ext.getCmp('MyNewsView');
						if (gridPanel != null) {
							gridPanel.getUpdater().update(__ctxPath+ '/sjsc/myTopNewsMyWork.do?limit=8');
						}
						
						//刷新公告搜索
						var gridPanel = Ext.getCmp('SearchNewsGrid');
						if (gridPanel != null) {
							//本地分页，使用load()
							gridPanel.getStore().load();
						}
						
						this.close();
					}
				});
			}

		});